//
//  WaitHUD.swift
//  ShiZhe
//
//  Created by 陈卿伟 on 16/8/31.
//  Copyright © 2016年 陈卿伟. All rights reserved.
//

import UIKit

class WaitHUD: UIView {
    var dot1:UIView!
    var dot2:UIView!
    var dot3:UIView!
    
    override init(frame: CGRect) {
        dot1 = UIView()
        dot2 = UIView()
        dot3 = UIView()
        super.init(frame: frame)
        self.createBlackBG()
        self.createDot()
        self.animateForDot1()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}

//MARK:--UI设置
extension WaitHUD{
    
    
    //创建一个透明背景
    func createBlackBG(){
        let bgView = UIView(frame: MainBounds)
        bgView.backgroundColor = UIColor.blackColor()
        bgView.alpha = 0.1
        self.addSubview(bgView)
    }
    
    //创建三个小白点
    func createDot(){
        dot1.frame = CGRect(x: 157*SCALEW, y: 262*SCALEH, width: 12*SCALEW, height: 12*SCALEW)
        dot1.backgroundColor = Theme.BlueHUD
        dot1.layer.cornerRadius = 6*SCALEW
        self.addSubview(dot1)
        
        dot2.frame = CGRect(x: 181*SCALEW, y: 262*SCALEH, width: 12*SCALEW, height: 12*SCALEW)
        dot2.backgroundColor = Theme.BlueHUD
        dot2.layer.cornerRadius = 6*SCALEW
        self.addSubview(dot2)
        
        dot3.frame = CGRect(x: 205*SCALEW, y: 262*SCALEH, width: 12*SCALEW, height: 12*SCALEW)
        dot3.backgroundColor = Theme.BlueHUD
        dot3.layer.cornerRadius = 6*SCALEW
        self.addSubview(dot3)
    }
    
}

//MARK:--小圆点的碰撞
extension WaitHUD{
    //小圆点1点动画
    func animateForDot1(){
        UIView.animateWithDuration(0.2, delay: 0, options: .CurveEaseOut, animations: {
            self.dot1.center.x -= 15
            }) { (end) in
                UIView.animateWithDuration(0.2, delay: 0, options: .CurveEaseIn, animations: {
                    self.dot1.center.x += 15
                }) { (end) in
                    self.animateForDot3()
                }
        }
    }
    
    //小圆点3点动画
    func animateForDot3(){
        UIView.animateWithDuration(0.2, delay: 0, options: .CurveEaseOut, animations: {
            self.dot3.center.x += 15
        }) { (end) in
            UIView.animateWithDuration(0.2, delay: 0, options: .CurveEaseIn, animations: {
                self.dot3.center.x -= 15
            }) { (end) in
                self.animateForDot1()
            }
        }
    }
}








